﻿#define DEBUG_AGENT
using System.Windows;
using Microsoft.Phone.Scheduler;
using System;
using Microsoft.Phone.Shell;


namespace BackAgent
{
    public class ScheduledAgent : ScheduledTaskAgent
    {
        private static volatile bool _classInitialized;

        public ScheduledAgent()
        {
            if (!_classInitialized)
            {
                _classInitialized = true;
              
                Deployment.Current.Dispatcher.BeginInvoke(delegate
                {
                    Application.Current.UnhandledException += ScheduledAgent_UnhandledException;
                });
            }
        }

       
        private void ScheduledAgent_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
            
                System.Diagnostics.Debugger.Break();
            }
        }

      
       
        protected override void OnInvoke(ScheduledTask task)
        {
            if (task is PeriodicTask)
            {
                Geo g = new Geo();
                g.whereamI();
                LiveTileHelper.UpdateTile();
                updatecontacts c = new updatecontacts();
                c.check();
                
            }
           
//#if(DEBUG_AGENT)

//            ScheduledActionService.LaunchForTest("Quick Task", TimeSpan.FromSeconds(6));

//#endif
            NotifyComplete();
        }
    }
}